//
//  MyMainCell.m
//  JinFuThree
//
//  Created by 毛韶谦 on 2018/9/1.
//  Copyright © 2018年 毛韶谦. All rights reserved.
//

#import "MyMainCell.h"

@interface MyMainCell()

@property (nonatomic,strong)UIImageView * headImgV;
@property (nonatomic,strong)UILabel * headTitleLab;
@property (nonatomic,strong)UILabel * subTitleLab;
@property (nonatomic,strong)UIImageView * arrowImgV;
@property (nonatomic,strong)UIView * bottomLineView;

@end

@implementation MyMainCell

+(instancetype)cellWithTableview:(UITableView *)tableview {
    MyMainCell * cell = [tableview dequeueReusableCellWithIdentifier:UserInfoITTACellIdentify];
    if (cell == nil) {
        
        cell = [[MyMainCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:UserInfoITTACellIdentify ];
    }
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

-(void)fillData:(id)data {
    CellModel * model = data;
    _headImgV.image = [UIImage imageNamed:model.image];
    _headTitleLab.text = model.title;
    _subTitleLab.text = model.subTitle;
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [self setUpViews];
    }
    
    return self;
}

-(void)setUpViews {
    
    _headImgV = [[UIImageView alloc]initWithFrame:CGRectZero];
    [self.contentView addSubview:_headImgV];
    
    _headTitleLab =[[UILabel alloc]initWithFrame:CGRectZero];
    _headTitleLab.font = [UIFont systemFontOfSize:15];
    _headTitleLab.textColor = ThemeMaoBlackColor;
    [self.contentView addSubview:_headTitleLab];
    
    _subTitleLab = [[UILabel alloc]initWithFrame:CGRectZero];
    _subTitleLab.font = [UIFont systemFontOfSize:12];
    _subTitleLab.textAlignment = NSTextAlignmentRight;
    _subTitleLab.textColor = ThemeMaoBackgroundColor;
    [self.contentView addSubview:_subTitleLab];
    
    _arrowImgV = [[UIImageView alloc]initWithFrame:CGRectZero];
    _arrowImgV.image = [UIImage imageNamed:@"ic_chevron_right"];
    _arrowImgV.contentMode = UIViewContentModeScaleAspectFit;
    [self.contentView addSubview:_arrowImgV];
    
    _bottomLineView = [[UIView alloc]initWithFrame:CGRectZero];
    _bottomLineView.backgroundColor = HexColor(0xf0efef);
    [self.contentView addSubview:_bottomLineView];
    
    
    [self layoutViews];
}

-(void)layoutViews {
    CGFloat diatance = ApplicationBackGauge+8;
    
    [_headImgV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.mas_equalTo(self.mas_centerY).offset(0);
        make.left.mas_equalTo(self.mas_left).offset(diatance);
        make.size.mas_equalTo(CGSizeMake(24, 24));
        
    }];
    
    [_headTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.mas_equalTo(self.mas_centerY).offset(0);
        make.left.mas_equalTo(self.headImgV.mas_right).offset(12);
        make.height.mas_equalTo(@(22));
        make.width.mas_equalTo(@(100));
    }];
    
    [_subTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.mas_equalTo(self.mas_centerY).offset(0);
        make.right.mas_equalTo(self.arrowImgV.mas_left).offset(-2);
        make.left.mas_equalTo(self.headTitleLab.mas_right).offset(10);
        make.height.mas_equalTo(@(22));
    }];
    
    [_bottomLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.height.mas_equalTo(@(0.5));
        make.left.mas_equalTo(self.mas_left).offset(diatance);
        make.right.mas_equalTo(self.mas_right).offset(-diatance);
        make.bottom.mas_equalTo(self.mas_bottom).offset(0);
    }];
    
    [_arrowImgV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.mas_equalTo(self.mas_centerY).offset(0);
        make.right.mas_equalTo(self.mas_right).offset(-ApplicationBackGauge-10);
        make.size.mas_equalTo(CGSizeMake(20,20));
    }];
    
}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end
